/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import who.tmap.ui.util.DataUIHelper;
import who.tmap.ui.util.MapUIHelper;
/**
 * @author stl
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class JDialogUsePolygonNameForAttrs extends JDialog {

	private String polygonColumnName;
	private boolean cancelled =true;
	
	private JPanel jContentPane = null;
	private JPanel jPanelInfo = null;
	private JLabel jLabelJoinIDColumnName = null;
	private JPanel jPanelButtons = null;
	private JButton jButtonOK = null;
	private JButton jButtonCancel = null;
	
	private JTextField jTextFieldPolygonColumnName = null;
	private JLabel jLabelDataColumnName = null;

	private JLabel jLabelDataColumnType = null;

	private JComboBox jComboBoxDataColumnType = null;

	private JPanel jPanelTop = null;

	private JLabel jLabelTopInfo = null;
	private JTextField jTextFieldDataColumnName = null;

	/**
	 * This is the default constructor
	 */
	public JDialogUsePolygonNameForAttrs( Frame parent, boolean modal, String polygonColumnName ) {
		super( parent, modal );
		
		this.polygonColumnName =polygonColumnName;
		
		initialize();
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setTitle("Populate join ID name attributes");
		this.setResizable(false);
		this.setBounds(new java.awt.Rectangle(0,0,554,213));
		this.setContentPane(getJContentPane());
		this.setLocationRelativeTo( null );
		
		getRootPane().setDefaultButton( getJButtonOK() );
	}
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if(jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(5,5,5,5));
			jContentPane.add(getJPanelTop(), java.awt.BorderLayout.NORTH);
			jContentPane.add(getJPanelName(), java.awt.BorderLayout.CENTER);
			jContentPane.add(getJPanelButtons(), java.awt.BorderLayout.SOUTH);
		}
		return jContentPane;
	}
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanelName() {
		if (jPanelInfo == null) {
			jLabelDataColumnType = new JLabel();
			jLabelDataColumnType.setText("Data column type");
			jLabelDataColumnName = new JLabel();
			jLabelDataColumnName.setText("Data column name");
			GridLayout gridLayout = new GridLayout(3,2,5,5);
			jLabelJoinIDColumnName = new JLabel();
			jPanelInfo = new JPanel();
			jLabelJoinIDColumnName.setText("Join ID column name");
			jPanelInfo.setLayout(gridLayout);
			jPanelInfo.add(jLabelJoinIDColumnName, null);
			jPanelInfo.add(getJTextFieldJoinIDColumnName(), null);
			jPanelInfo.add(jLabelDataColumnName, null);
			jPanelInfo.add(getJTextFieldDataColumnName(), null);
			jPanelInfo.add(jLabelDataColumnType, null);
			jPanelInfo.add(getJComboBoxDataColumnType(), null);
		}
		return jPanelInfo;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanelButtons() {
		if (jPanelButtons == null) {
			jPanelButtons = new JPanel();
			jPanelButtons.add(getJButtonOK(), null);
			jPanelButtons.add(getJButtonCancel(), null);
		}
		return jPanelButtons;
	}
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setText("OK");
			jButtonOK.setSelected(true);
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					cancelled =false;
					setVisible( false );
				}
			});
		}
		return jButtonOK;
	}
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getJButtonCancel() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setText("Cancel");
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
					setVisible( false );					
				}
			});
		}
		return jButtonCancel;
	}

	/**
	 * This method initializes jTextFieldPolygonName	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getJTextFieldJoinIDColumnName() {
		if (jTextFieldPolygonColumnName == null) {
			jTextFieldPolygonColumnName = new JTextField(polygonColumnName);
		}
		return jTextFieldPolygonColumnName;
	}
	
	/**
	 * This method initializes jComboBoxDataColumnType	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	public JComboBox getJComboBoxDataColumnType() {
		if (jComboBoxDataColumnType == null) {
			jComboBoxDataColumnType = new JComboBox( DataUIHelper.AttrTypesUI );
			jComboBoxDataColumnType.setSelectedItem( DataUIHelper.DEFAULT_DATA_ATTR_TYPE_UI );
		}
		return jComboBoxDataColumnType;
	}
	/**
	 * This method initializes jPanelTop	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelTop() {
		if (jPanelTop == null) {
			jLabelTopInfo = new JLabel();
			jLabelTopInfo.setText("TMap can populate the data window\n with the polygons names (Join IDs) from the base map\n");
			jLabelTopInfo.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
			jPanelTop = new JPanel();
			jPanelTop.add(jLabelTopInfo,null);
		}
		return jPanelTop;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getJTextFieldDataColumnName() {
		if (jTextFieldDataColumnName == null) {
			jTextFieldDataColumnName = new JTextField();
			jTextFieldDataColumnName.setText( MapUIHelper.DEFAULT_DATA_COLUMN_NAME );
		}
		return jTextFieldDataColumnName;
	}
	
	public boolean isCancelled() {
		return cancelled;
	}	
	
 }  //  @jve:decl-index=0:visual-constraint="10,10"  
